package com.ayz.gateway.sdk.gatawayService.config;

import com.ayz.gateway.client.GrpcClientConfig;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName GatewayServiceConfig
 * @Description TODO: 网关服务的配置
 * @Author 快乐的星球
 * @Date 2023/5/26 22:02
 * @Version 1.0
 **/
@Data
public class GatewayServiceConfig {
    /**
     * 服务端通信地址列表
     */
    private List<String> serverAddressList;
    /**
     * GRPC客户端通信组件的配置
     */
    private GrpcClientConfig grpcClientConfig;
    /**
     * 网关服务向网关注册中心注册请求的超时时间是 1000ms
     */
    private long registryGatewayServiceTimeoutMills= TimeUnit.SECONDS.toMillis(3);
    /**
     * 请求的重试次数默认是3次
     */
    private long retires=3;
    /**
     * 向网关注册中心注册任务心跳的执行周期
     * 默认每隔10S执行一次
     */
    private long registryGatewayServiceTaskTime=TimeUnit.SECONDS.toMillis(10);

    public GatewayServiceConfig(List<String> serverAddressList, GrpcClientConfig grpcClientConfig) {
        this.serverAddressList = serverAddressList;
        this.grpcClientConfig = grpcClientConfig;
    }

    public GatewayServiceConfig() {
        this.serverAddressList=new ArrayList<>();
        this.grpcClientConfig=new GrpcClientConfig();
    }

    public void addServerAddress(String address){
        if(this.serverAddressList==null){
            this.serverAddressList=new ArrayList<>();
        }
        this.serverAddressList.add(address);
    }

    public void addServerAddressList(List<String> addressList){
        if(this.serverAddressList==null){
            this.serverAddressList=new ArrayList<>();
        }
        this.serverAddressList.addAll(addressList);
    }


}
